<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Recibo_1 extends MN_Controller {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper(array('url', 'form'));
        $this->load->library('ion_auth');
    }

    public function genera() {
      if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_secretary()  ) {
            $this->session->set_flashdata('message', 'No pertence al grupo de Docentes');
            redirect('auth/login', 'refresh');
        }
        $this->data['user'] = $this->ion_auth->get_user_username();
        
        $this->load->model('Matricula_Model');
        $this->load->model('Institucion_Model');

        $this->data['cuentas']=$this->Institucion_Model->getCuentasInstitucionNombre("INSTITUTO TECNOLOGICO SUPERIOR SUDAMERICANO LOJA");
        $this->data['id_matr'] = $this->input->post('id_matr'); 

        $this->data['apellido_pers'] = $this->input->post('apellido_pers');
        $this->data['nombre_pers'] = $this->input->post('nombre_pers');
        $this->data['cedula_pers'] = $this->input->post('cedula_pers');
        $this->data['fono_pers'] = $this->input->post('fono_pers');
        $this->data['celular_pers'] = $this->input->post('celular_pers');
        $this->data['direccion_pers'] = $this->input->post('direccion_pers');
        $this->data['monto_canc_matr'] = $this->input->post('monto_canc_matr');
        $this->data['nom_doc_pago_mat'] = $this->input->post('nom_doc_pago_mat');
        $this->data['nro_comp_pago_mat'] = $this->input->post('nro_comp_pago_mat');
        $this->data['lote_doc_pago_mat'] = $this->input->post('lote_doc_pago_mat');
        $this->data['ref_doc_pago_mat'] = $this->input->post('ref_doc_pago_mat');
        $this->data['monto_efec_doc_pago'] = $this->input->post('monto_efec_doc_pago');
        $this->data['monto_rest_doc_pago'] = $this->input->post('monto_rest_doc_pago');
        $this->data['tipo_doc_pago_mat'] = $this->input->post('tipo_doc_pago_mat');
        $this->data['fechadep_doc_pago_mat'] = $this->input->post('fechadep_doc_pago_mat');
        //
        if(isset($_POST['nrodepos'])&& $_POST['nrodepos']>1 ){
            
                    $this->data['monto_rest_doc_pago31'] = $this->input->post('monto_rest_doc_pago31');
                    $this->data['nrodepos'] = $_POST['nrodepos'];
                    //echo ($_POST['nrodepos']);
                    switch ($_POST['nrodepos']){
                        case 2:
                            $this->data['nom_doc_pago_mat32'] = $this->input->post('nro_comp_pago_mat32');
                            $this->data['nro_comp_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['lote_doc_pago_mat32'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['fechadep_doc_pago_mat12'] = $this->input->post('fechadep_doc_pago_mat12');
                            $this->data['monto_rest_doc_pago32'] = $this->input->post('monto_rest_doc_pago32');


                            break;

                        case 3:
                            $this->data['nom_doc_pago_mat32'] = $this->input->post('nro_comp_pago_mat32');
                            $this->data['nro_comp_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['lote_doc_pago_mat32'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['fechadep_doc_pago_mat12'] = $this->input->post('fechadep_doc_pago_mat12');
                            $this->data['monto_rest_doc_pago32'] = $this->input->post('monto_rest_doc_pago32');


                            $this->data['nom_doc_pago_mat33'] = $this->input->post('nro_comp_pago_mat33');
                            $this->data['nro_comp_pago_mat33'] = $this->input->post('ref_doc_pago_mat33');
                            $this->data['lote_doc_pago_mat33'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat33'] = $this->input->post('ref_doc_pago_mat33');
                            $this->data['fechadep_doc_pago_mat13'] = $this->input->post('fechadep_doc_pago_mat13');
                            $this->data['monto_rest_doc_pago33'] = $this->input->post('monto_rest_doc_pago33');



                            break;

                        case 4:
                            $this->data['nom_doc_pago_mat32'] = $this->input->post('nro_comp_pago_mat32');
                            $this->data['nro_comp_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['lote_doc_pago_mat32'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat32'] = $this->input->post('ref_doc_pago_mat32');
                            $this->data['fechadep_doc_pago_mat12'] = $this->input->post('fechadep_doc_pago_mat12');
                            $this->data['monto_rest_doc_pago32'] = $this->input->post('monto_rest_doc_pago32');


                            $this->data['nom_doc_pago_mat33'] = $this->input->post('nro_comp_pago_mat33');
                            $this->data['nro_comp_pago_mat33'] = $this->input->post('ref_doc_pago_mat33');
                            $this->data['lote_doc_pago_mat33'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat33'] = $this->input->post('ref_doc_pago_mat33');
                            $this->data['fechadep_doc_pago_mat13'] = $this->input->post('fechadep_doc_pago_mat13');
                            $this->data['monto_rest_doc_pago33'] = $this->input->post('monto_rest_doc_pago33');

                            $this->data['nom_doc_pago_mat34'] = $this->input->post('nro_comp_pago_mat34');
                            $this->data['nro_comp_pago_mat34'] = $this->input->post('ref_doc_pago_mat34');
                            $this->data['lote_doc_pago_mat34'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat34'] = $this->input->post('ref_doc_pago_mat34');
                            $this->data['fechadep_doc_pago_mat14'] = $this->input->post('fechadep_doc_pago_mat14');
                            $this->data['monto_rest_doc_pago34'] = $this->input->post('monto_rest_doc_pago34');

                            break;
                        
                    }
                    
                    
                }
        echo ($_POST['nroefecdepos']);
        if(isset($_POST['nroefecdepos'])&& $_POST['nroefecdepos']>1 ){
                    $this->data['monto_rest_doc_pago61'] = 0;
                    $this->data['nroefecdepos'] = $_POST['nroefecdepos'];
                    switch ($_POST['nroefecdepos']){
                        case 2:
                            $this->data['nom_doc_pago_mat62'] = $this->input->post('nro_comp_pago_mat62');
                            $this->data['nro_comp_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['lote_doc_pago_mat62'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['fechadep_doc_pago_mat22'] = $this->input->post('fechadep_doc_pago_mat22');
                            $this->data['monto_rest_doc_pago62'] = $this->input->post('monto_rest_doc_pago62');


                            break;

                        case 3:
                            $this->data['nom_doc_pago_mat62'] = $this->input->post('nro_comp_pago_mat62');
                            $this->data['nro_comp_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['lote_doc_pago_mat62'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['fechadep_doc_pago_mat22'] = $this->input->post('fechadep_doc_pago_mat22');
                            $this->data['monto_rest_doc_pago62'] = $this->input->post('monto_rest_doc_pago62');


                            $this->data['nom_doc_pago_mat63'] = $this->input->post('nro_comp_pago_mat63');
                            $this->data['nro_comp_pago_mat63'] = $this->input->post('ref_doc_pago_mat63');
                            $this->data['lote_doc_pago_mat63'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat63'] = $this->input->post('ref_doc_pago_mat63');
                            $this->data['fechadep_doc_pago_mat23'] = $this->input->post('fechadep_doc_pago_mat23');
                            $this->data['monto_rest_doc_pago63'] = $this->input->post('monto_rest_doc_pago63');


                            break;

                        case 4:
                            $this->data['nom_doc_pago_mat62'] = $this->input->post('nro_comp_pago_mat62');
                            $this->data['nro_comp_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['lote_doc_pago_mat62'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat62'] = $this->input->post('ref_doc_pago_mat62');
                            $this->data['fechadep_doc_pago_mat22'] = $this->input->post('fechadep_doc_pago_mat22');
                            $this->data['monto_rest_doc_pago62'] = $this->input->post('monto_rest_doc_pago62');


                            $this->data['nom_doc_pago_mat63'] = $this->input->post('nro_comp_pago_mat63');
                            $this->data['nro_comp_pago_mat63'] = $this->input->post('ref_doc_pago_mat63');
                            $this->data['lote_doc_pago_mat63'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat63'] = $this->input->post('ref_doc_pago_mat63');
                            $this->data['fechadep_doc_pago_mat23'] = $this->input->post('fechadep_doc_pago_mat23');
                            $this->data['monto_rest_doc_pago63'] = $this->input->post('monto_rest_doc_pago63');

                            $this->data['nom_doc_pago_mat64'] = $this->input->post('nro_comp_pago_mat64');
                            $this->data['nro_comp_pago_mat64'] = $this->input->post('ref_doc_pago_mat64');
                            $this->data['lote_doc_pago_mat64'] = 'NINGUNO';
                            $this->data['ref_doc_pago_mat64'] = $this->input->post('ref_doc_pago_mat64');
                            $this->data['fechadep_doc_pago_mat24'] = $this->input->post('fechadep_doc_pago_mat24');
                            $this->data['monto_rest_doc_pago64'] = $this->input->post('monto_rest_doc_pago64');


                            break;
                        
                    }

                    
                }
        
        //fechadep_doc_pago_mat2
        //$this->data['ide_lec']=$this->input->post('ide_lec');
        $this->data['concepto'] = $this->input->post('concepto');
        $this->data['ide_lec'] = $this->input->post('ide_lec');
        //$nro=$this->Matricula_Model->getNroCredito($this->input->post('ide_lec'))+1;
        
        //$this->data['nro_recibo'] =$nro;
        $this->data['pagina'] =$this->uri->segment(3);
        
        //echo $this->uri->segment(3);
        
        //$url=$_SERVER['REQUEST_URI'];
         if($this->session->flashdata('enviardetalle')){
            $detalle=$this->session->flashdata('enviardetalle');   
        }else{
            $detalle="";
        }
        $this->data['detalle'] = $detalle;

       
        $this->_render('recibo/new_1');
    }

    public function ingresodatos() {
      if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_secretary()  ) {
            $this->session->set_flashdata('message', 'No pertence al grupo de Docentes');
            redirect('auth/login', 'refresh');
        }
        $this->data['user'] = $this->ion_auth->get_user_username();
        
        
         $this->load->helper('numeros');
         $this->load->model('Matricula_Model');
        if($this->session->flashdata('detalle')){
         $detalle=$this->session->flashdata('detalle');   
        }else{
            $detalle="";
        }
          
        //print_r($detalle);
        
        $id_matr=$this->input->post('id_matr');
        
        
        $this->data['apellido_pers'] = $this->input->post('apellido_pers');
        $this->data['nombre_pers'] = $this->input->post('nombre_pers');
        $this->data['cedula_pers'] = $this->input->post('cedula_pers');
        $this->data['fono_pers'] = $this->input->post('fono_pers');
        $this->data['celular_pers'] = $this->input->post('celular_pers');
        $this->data['direccion_pers'] = $this->input->post('direccion_pers');
        $this->data['email_inst_pers'] = $this->input->post('email_inst_pers');
        $this->data['monto_canc_matr'] = $this->input->post('monto_canc_matr');
        $this->data['monto_letras'] = num_to_letras($this->input->post('monto_canc_matr'));
        $this->data['nom_doc_pago_mat'] = $this->input->post('nom_doc_pago_mat');

        $this->data['nro_comp_pago_mat'] = $this->input->post('nro_comp_pago_mat');
        $this->data['lote_doc_pago_mat'] = $this->input->post('lote_doc_pago_mat');
        $this->data['ref_doc_pago_mat'] = $this->input->post('ref_doc_pago_mat');
        $this->data['monto_efec_doc_pago'] = $this->input->post('monto_efec_doc_pago');
        $this->data['monto_rest_doc_pago'] = $this->input->post('monto_rest_doc_pago');
        $this->data['fechadep_doc_pago_mat'] = $this->input->post('fechadep_doc_pago_mat');
        
        $this->data['tipo_doc_pago_mat'] = $this->input->post('tipo_doc_pago_mat');
        $this->data['pagina'] = $this->input->post('pagina');
        $this->data['concepto'] = $this->input->post('concepto');
        $nro = $this->Matricula_Model->getNroRecibo($this->input->post('ide_lec')) + 1;
        $this->data['nro_recibo'] = $nro;
        $this->data['detalle'] = $detalle;
        
        //$nro=$this->Matricula_Model->getNroRecibo($this->input->post('ide_lec'))+1;

        $recibo = array(
            "nro_recibo_mat" =>  $nro,
            "tipo_doc_pago_mat" => $this->input->post('tipo_doc_pago_mat'),
            "nom_doc_pago_mat" =>$this->input->post('nom_doc_pago_mat'),
            "nro_comp_pago_mat" => $this->input->post('nro_comp_pago_mat'),
            "lote_doc_pago_mat" => $this->input->post('lote_doc_pago_mat'),
            "ref_doc_pago_mat" => $this->input->post('ref_doc_pago_mat'),
            "id_matr" => $id_matr);
        //print_r($recibo);
        
        $this->Matricula_Model->grabarRecibo($recibo);
        $montos = array(
            "monto_efec_doc_pago" => $this->input->post('monto_efec_doc_pago'),
            "monto_rest_doc_pago" =>$this->input->post('monto_rest_doc_pago'),
            "id_matr" => $id_matr);
        $this->Matricula_Model->grabarMontos($montos);
        $fechadep=$this->input->post('fechadep_doc_pago_mat');
        if (!empty($fechadep)) {
            $fechadep=date("Y-m-d", strtotime($this->input->post('fechadep_doc_pago_mat'), 0));
            $this->Matricula_Model->actualizafechadeposito($fechadep, $id_matr);
        }else{
            $this->Matricula_Model->actualizafechadeposito($fechadep, $id_matr);
        }

        $html = $this->load->view('recibo/recibo_pago', $this->data, true);
        $path = $this->dompdf_lib->createPDF($html, 'myfilename1', false,"a3");

        $this->data['path'] = $path;

        $this->_render('recibo/reporte1');
    }

}


